'use strict';

const Controller = require('egg').Controller;

class DeleteCartController extends Controller {
  async index() {
    
    const { ctx } = this;
    var {id} = ctx.request.body
    // var res = await ctx.model.User.updateOne({},{$pull:{cartList:{_id:id}}})
    // console.log(res);
    try{
      var res = await ctx.model.User.updateOne({},{$pull:{cartList:{_id:id}}});
      if(res.nModified){
          ctx.body = {
              code:200,
              msg:"删除成功"
          }
      }
    }catch(err){
        ctx.body = {
            code:400,
            msg:"输入删除的参数不合法"
        }
    }
  }
}

module.exports = DeleteCartController;
